import { getGoodsList,delGoodsList,addGoodsList,setGoodsList } from '@/api/goods'

const state = {
	goodsList: [],
	total:0,
	// codeID:''
}

const mutations = {
	updateGoodsList(state, payload) {
		state.goodsList = payload
	},
	updateTotal(state, payload) {
		state.total = payload;
	},
	// delGoods(state,payload){
	// 	state.codeID = payload
	// }
}

const actions = {
	async getGoodsList({ commit }, payload) {
		const result = await getGoodsList({
			pageCurrent: payload.pageCurrent,
			pageSize: payload.pageSize
		});
		if (result) {
		  	commit("updateGoodsList", result.result.books.list);
		  	commit("updateTotal", result.result.books.total);
		}
	},
	async delGoodsList({ commit },payload){
		const result = await delGoodsList({
			code: payload.code
		})
	},
	async addGoodsList({ commit }, payload) {
		const result = await addGoodsList({
			form:payload
		})
	},
	async setGoodsList({ commit }, payload) {
		const result = await setGoodsList({
			form:payload
		})
	}
}

export default {
	namespaced: true,
	state,
	mutations,
	actions
}
